package com.ssyc.student.util;

import android.content.Context;

import com.ssyc.student.R;

import java.util.Map;

/**
 * Created by Administrator on 2018/6/5 0005.
 */

public class CommitUtil {

    /**
     * 获取正确答题的数量
     *
     * @param map
     * @return
     */
    public static int getRightAnswerCount(Map<Integer, Boolean> map) {
        int totalCount = 0;
        if (null == map || map.size() == 0) {
            return 0;
        } else {
            for (int i = 0; i < map.size(); i++) {
                if (map.get(i) == true) {
                    //表示当前选择正确
                    totalCount++;
                }
            }
        }
        return totalCount;
    }

    /**
     * 获取当前位置选择的答案在服务器返回的的当前题目提供的选项中的索引值
     *
     * @param map
     * @return
     */
    public static int getChooseAnswerIndex(Context context, int pos, Map<Integer, String> map) {
        int index = -1;
        String[] letters = context.getResources().getStringArray(R.array.base_letters);
        for (int i = 0; i < letters.length; i++) {
            if (map.get(pos).equals(letters[i])) {
                index = i;
                break;
            }
        }
        return index;
    }
}
